package COM.YNNYZY;

import java.util.ArrayList;
import java.util.Scanner;

public class KTV {
      private  ArrayList< String >  songList = new ArrayList<>();
    public static void main(String[] args) {
        KTV system = new KTV();
        system.start();
    }
    public  void start (){
        Scanner scanner = new Scanner(System.in);
        System.out.println("--------点歌系统-----------");  System.out.println("--------点歌系统-----------");
        System.out.println("歌曲添加至播放列表");
        System.out.println("歌曲置顶");
        System.out.println("歌曲播放向前一位");
        System.out.println("查看歌曲播放列表");
        System.out.println("删除列表歌曲信息");
        System.out.println("提出");
        int choice;
        while (true){
            System.out.println("请输入(1-6)的指令");
            choice  = scanner.nextInt();
            scanner.nextLine(); // 消除换行符
            switch (choice){
                case 1:
                    this.deletesong(scanner);
                break;
                case 2:
                    this.moveSongUp(scanner);
                    break;
                case 3:
                    this.moveSongUp(scanner);
                    break;
                case 4:
                    this.shwSongs();
                    break;
                case 5:
                    this.deletesong(scanner);
                    break;
                case 6:
                    System.out.println("退出点歌系统");
                    return;
                default:
                    System.out.println("指令无效，需重新输入");
            }
        }
    }
    private  void  moveSongUp(Scanner scanner){
        System.out.println("请输入您要向前移动的歌曲");
        String songName = scanner.nextLine();
        int index = songList.indexOf(songName);
        if (index != -1 && index > 0 ){
            songList.remove(index);
            songList.add(index - 1, songName);
            System.out.println("歌曲已经向前移动，当前列表："+ songList);
        }else {
            System.out.println("歌曲不存在或已经在第一位，无法前移");
        }
    }
    private  void shwSongs(){
        System.out.println("当前歌曲列表："+ songList);
    }
    private void deletesong(Scanner scanner){
        System.out.println("请输入您要删除的歌曲");
        String songName = scanner.nextLine();
        int index = songList.indexOf(songName);
        if (index != -1) {
        songList.remove(index);
        System.out.println("已删除歌曲，当前歌曲列表："+ songList);
        }else {
            System.out.println("歌曲不存在，无法删除");
        }
    }
}
